<template>
     <el-dialog
      :close-on-click-modal="false"
      :visible.sync="supnoVisible"
      :before-close="handleClose"
      top="5vh"
    >
    <template slot="title">
        <div :style="titleColor">搜索</div>
      </template>
      <el-form :inline="true" class="demo-form-inline filter">
        <el-form-item label="供应商名称">
          <el-input
            v-model="listQuerySearch.fsupname"
            clearable
            class="filter-item"
            placeholder="请输入供应商名称"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            round
            size="medium"
            class="filter-item"
            :style="{background:buttonColor.lookup,color:buttonColor.color}"
            @click="searchFilter"
          >查找</el-button
          >
        </el-form-item>
      </el-form>

      <!-- 查询结果 -->
      <el-table
        v-loading="listLoadingSearch"
        :data="searchList"
        :header-cell-style="tableColor"
        stripe
        element-loading-text="正在查询中。。。"
        border
        fit
        highlight-current-row
        height="300"
      >
        <el-table-column align="center" label="供应商编号" prop="fsupno" />
        <el-table-column align="center" label="供应商名称" prop="fsupname" />
        <el-table-column
          align="center"
          label="选择"
          class-name="small-padding"
        >
          <template slot-scope="scope">
            <el-button
              :style="{background:buttonColor.confirm,color:buttonColor.color}"
              round
              size="small"
              class="button-margin"
              @click="searchData(scope.row)"
            >确定</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="totalSearch > 0"
        :total="totalSearch"
        :page.sync="listQuerySearch.page"
        :limit.sync="listQuerySearch.limit"
        style="padding:14px 10px !important"
        @pagination="getSearchList"
      />
    </el-dialog>
</template>

<script>
import Pagination from '@/components/Pagination'
import { listtsSupplier } from '@/api/tsSupplier'
import {buttonColor,titleColor} from '@/filters/index'
export default {
  name: 'SupnoDialog',
  components: { Pagination },
  props:{
    supnoVisible: {
      required: true,
      type: Boolean
    },
    tableColor: {
      required: true,
      type: Object
    },
  },
  data(){
    return{
      titleColor,
      buttonColor,
      selectList:[],
      searchList: null,
      listLoadingSearch: true,
      totalSearch: 0,
      listQuerySearch: {
        page: 1,
        limit: 20,
        fsupname: undefined,
        sort: 'create_time',
        order: 'desc'
      },
    }
  },
  created(){
     this.getSearchList()
  },
  methods:{
    getSearchList() {
      this.listLoadingSearch = true
      const temp = {
        fsiteNo:this.$store.state.user.fsiteNo,
        page:this.listQuerySearch.page,
        limit:this.listQuerySearch.limit,
        sort: 'create_time',
        order: 'desc',
        fsupname:this.listQuerySearch.fsupname,
      }

       listtsSupplier(temp)
      .then(response => {
        this.searchList = response.data.data.list
        this.totalSearch = response.data.data.total
          this.listLoadingSearch = false
      })
      .catch(() => {
        this.searchList = []
        this.totalSearch = 0
          this.listLoadingSearch = false
      })

    },

    searchFilter() {
      this.listQuerySearch.page = 1
      this.getSearchList()
    },

    searchData(row) {
     this.$emit('update:supnoVisible', false)
      this.$emit('supnoDialog', { data: row })
    },

     // 弹窗点击关闭前的回调
    handleClose(){
      this.$emit('update:supnoVisible', false)
    }

  },
}
</script>
